﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Common.Library;
using OnlineVideos.UI;
using Common.Utilities;
using Social_Celebrities;
using Facebook;
using System.IO.IsolatedStorage;
namespace Social_Celebrities.Views
{
    public partial class AddAccount : PhoneApplicationPage
    {        
        public AddAccount()
        {
            InitializeComponent();
            LoadAds();
            Loaded += AddAccount_Loaded;
        }

        void AddAccount_Loaded(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(AppSettings.FaceBookAccessToken))
            {
                fbstatus.Text = "Log out"; ///Log Out
            }
            else
            {
                fbstatus.Text = "Log in";
            }

             TwitterLoginPage p = new TwitterLoginPage();
             if (p.getAccessToken() != null)
             {
                 twitstatus.Text = "Log out"; //Sign out
             }
             else
                 twitstatus.Text = "Log in";

             if (!string.IsNullOrEmpty(AppSettings.BloggerAccessToken))
             {
                 blogstatus.Text = "Log out";  //Sign out
             }
             else
                 blogstatus.Text = "Log in";
        }
        private void LoadAds()
        {
            try
            {
                PageHelper.LoadAdControl(LayoutRoot, AddAcct_Ad, 2);
            }
            catch (Exception ex)
            {
                Exceptions.SaveOrSendExceptions("Exception in LoadAds Method In AddAccount.xaml.cs file file", ex);
                string excepmess = "Exception in LoadAds Method In AddAccount.xaml.cs file.\n\n" + ex.Message + "\n\n StackTrace :- \n" + ex.StackTrace;
            }
        }

        private void FaceStack_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (string.IsNullOrEmpty(AppSettings.FaceBookAccessToken))
            {
                NavigationService.Navigate(new Uri("/Views/FacebookLoginPage.xaml", UriKind.Relative));
            }
        }

        private void TwitStack_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            TwitterLoginPage p = new TwitterLoginPage();
            if (p.getAccessToken() == null)
            {
                NavigationService.Navigate(new Uri("/Views/TwitterLoginPage.xaml", UriKind.Relative));
            }
        }

        private void BlogStack_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (string.IsNullOrEmpty(AppSettings.BloggerAccessToken))
            {
                NavigationService.Navigate(new Uri("/Views/BloggerLogin.xaml", UriKind.Relative));
            }
        }

        private void imgTitle_MouseEnter(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            NavigationService.Navigate(NavigationHelper.MainPanoramaPage);
        }

        private void fbstatus_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (fbstatus.Text == "Log out")
            {
                AppSettings.FaceBookAccessToken = "";
                fbstatus.Text = "Log in";
                NavigationService.GoBack();
            }
        }

        private void twitstatus_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            TwitterLoginPage p = new TwitterLoginPage();
            TweetSharp.OAuthAccessToken token;
            token = null;
            if (twitstatus.Text == "Log out")
            {
                IsolatedStorageSettings.ApplicationSettings["accessToken"] = token;
                token = null;
                twitstatus.Text = "Log in";
                NavigationService.GoBack();
            }
        }

        private void blogstatus_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (blogstatus.Text == "Log out")
            {
                AppSettings.BloggerAccessToken = "";
                blogstatus.Text = "Log in";
                NavigationService.GoBack();
            }
        }
    }
}